package com.snopy.leetcode.index1_1000.index101_200;

import com.snopy.leetcode.TreeNode;
import com.snopy.utils.DataFactoryUtil;

/**
 * @author snopy
 * @version 1.0.0
 * @classname Question101
 * @description 对称二叉树
 * 给你一个二叉树的根节点root,检查它是否轴对称
 * @email 77912204@qq.com
 * @date 2022/04/04 23:35
 */
public class Question101 {
    public static void main(String[] args) {
        Integer[] nums = new Integer[]{1,2,2,3,4,4,3};
        TreeNode root = DataFactoryUtil.buildTree(nums);
        boolean symmetric = isSymmetric(root);
        System.out.println(symmetric);
    }
    public static boolean isSymmetric(TreeNode root) {
        if (root==null){
            return false;
        }
        return isMirror(root,root);
    }
    public static boolean isMirror(TreeNode left,TreeNode right){
        if (left==null && right==null){
            return true;
        }
        if (left ==null || right == null){
            return false;
        }
        return (left.val == right.val)&&isMirror(left.left,right.right)&&isMirror(left.right,right.left);
    }
}
